import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Seting from './seting'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    resCode:"100000206",
    children: [{
      path: '/home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  ...Seting,
  {
    path: '/',
    hidden: true,
    component: Layout,
    children: [{
      path: 'user-center',
      name: 'UserCenter',
      component: () => import('@/views/user-center'),
      meta: { title: '用户中心', icon: 'dashboard' }
    }]
  },
  {
    path: '/qiyewx',
    component: () => import('@/views/login/qiyewx'),
    hidden: true
  },
  {
    path: '/forget',
    name:"ForgetPswd",
    component: () => import('@/views/login/forget'),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'hash', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export function addRouter(routes) {
  const newRouter = createRouter()
  newRouter.options.routes = routes
  router.matcher = newRouter.matcher // reset router
}

export default router
